﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web;

namespace Team4Mock.DAO
{
    public class ContactDAO
    {
        Helper h = new Helper();
        public DataTable GetData()
        {
            return h.GetData("Contact_Getdata");
        }
        public DataTable GetDataTrue()
        {
            return h.GetData("Contact_GetdataTrue");
        }
        public DataTable GetContactType()
        {
            return h.GetData("Contact_ContactType");
        }
        public DataTable GetContactBestMethod()
        {
            return h.GetData("Contact_ContactBestMethod");
        }
        public DataTable GetByID(int ID)
        {
            SqlParameter[] p;
            p = new SqlParameter[1];
            p[0] = new SqlParameter("@ContactID", ID);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("Contact_GetbyID", p);
        }
        public DataTable Search(int index,string fname,string sname)
        {
            SqlParameter[] p;
            p = new SqlParameter[3];
            p[0] = new SqlParameter("@index", index);
            p[0].SqlDbType = SqlDbType.Int;
            p[1] = new SqlParameter("@Fname", fname);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@Sname", sname);
            p[2].SqlDbType = SqlDbType.NVarChar;

            return h.GetData("Contact_Search", p);
        }
        public void InsertData(string fname,string sname,string know,string Offphone,string mobphone,string homephone,string email,int managerID,int contacttype,int bestcontact,string jobrole,string workbase,string jobtitle,int isactive)
        {
            SqlParameter[] p;
            p = new SqlParameter[14];
            p[0] = new SqlParameter("@FirstName", fname);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@SurName", sname);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@KnowAs", know);
            p[2].SqlDbType = SqlDbType.NVarChar;
            p[3] = new SqlParameter("@OfficePhone", Offphone);
            p[3].SqlDbType = SqlDbType.VarChar;
            p[4] = new SqlParameter("@MobilePhone", mobphone);
            p[4].SqlDbType = SqlDbType.VarChar;
            p[5] = new SqlParameter("@STHomePhone", homephone);
            p[5].SqlDbType = SqlDbType.VarChar;
            p[6] = new SqlParameter("@Email", email);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@ManagerID", managerID);
            p[7].SqlDbType = SqlDbType.Int;
            p[8] = new SqlParameter("@ContactType", contacttype);
            p[8].SqlDbType = SqlDbType.Int;
            p[9] = new SqlParameter("@BestContact", bestcontact);
            p[9].SqlDbType = SqlDbType.Int;
            p[10] = new SqlParameter("@JobRole", jobrole);
            p[10].SqlDbType = SqlDbType.NVarChar;
            p[11] = new SqlParameter("@WorkBase", workbase);
            p[11].SqlDbType = SqlDbType.NVarChar;
            p[12] = new SqlParameter("@JobTitle", jobtitle);
            p[12].SqlDbType = SqlDbType.NVarChar;
            p[13] = new SqlParameter("@IsActive", isactive);
            p[13].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Contact_Insert", p);
        }
        public void UpdateData(int id,string fname, string sname, string know, string Offphone, string mobphone, string homephone, string email, int managerID, int contacttype, int bestcontact, string jobrole, string workbase, string jobtitle, int isactive)
        {
            SqlParameter[] p;
            p = new SqlParameter[15];
            p[0] = new SqlParameter("@FirstName", fname);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@SurName", sname);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@KnowAs", know);
            p[2].SqlDbType = SqlDbType.NVarChar;
            p[3] = new SqlParameter("@OfficePhone", Offphone);
            p[3].SqlDbType = SqlDbType.VarChar;
            p[4] = new SqlParameter("@MobilePhone", mobphone);
            p[4].SqlDbType = SqlDbType.VarChar;
            p[5] = new SqlParameter("@STHomePhone", homephone);
            p[5].SqlDbType = SqlDbType.VarChar;
            p[6] = new SqlParameter("@Email", email);
            p[6].SqlDbType = SqlDbType.VarChar;
            p[7] = new SqlParameter("@ManagerID", managerID);
            p[7].SqlDbType = SqlDbType.Int;
            p[8] = new SqlParameter("@ContactType", contacttype);
            p[8].SqlDbType = SqlDbType.Int;
            p[9] = new SqlParameter("@BestContact", bestcontact);
            p[9].SqlDbType = SqlDbType.Int;
            p[10] = new SqlParameter("@JobRole", jobrole);
            p[10].SqlDbType = SqlDbType.NVarChar;
            p[11] = new SqlParameter("@WorkBase", workbase);
            p[11].SqlDbType = SqlDbType.NVarChar;
            p[12] = new SqlParameter("@JobTitle", jobtitle);
            p[12].SqlDbType = SqlDbType.NVarChar;
            p[13] = new SqlParameter("@IsActive", isactive);
            p[13].SqlDbType = SqlDbType.Int;
            p[14] = new SqlParameter("@ContactID", id);
            p[14].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("Contact_Update", p);
        }
    }
}